package com.patterns.memento;

public class Test {
	public static void main(String[] args) {
		
		StudentCareTaker taker = new StudentCareTaker();//记录备忘录
		
		Student student = new Student();
		student.setName("张三");
		student.setAge(18);
		taker.setMemento(student.memento());;//保存备份
		System.out.println("初始值:" + student);
		
		student.setName("李四");
		student.setAge(22);
		taker.setMemento(student.memento());;//保存备份
		System.out.println("修改一次:" + student);
		
		student.setName("王五");
		student.setAge(28);
		System.out.println("修改二次:" + student);//修改不备份
		
		student.recovery(taker.last());//回滚一次
		System.out.println("回滚到修改一:" + student);
		
		student.recovery(taker.last());//回滚一次
		System.out.println("回滚到初始值:" + student);
		
	}
}
